package com.site.wisdom_construction.controller.partyConstructionModule;

import com.site.wisdom_construction.responseEntity.JsonResult;
import com.site.wisdom_construction.responseEntity.OneDataResult;
import com.site.wisdom_construction.responseEntity.Page;
import com.site.wisdom_construction.service.partyConstructionModule.PartyConstructionPhotoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author daiyifei
 * @Date 2022/1/17
 * @Description
 */
@Api(tags = "党建宣传图片接口")
@RestController
@RequestMapping("PartyConstructionPhoto")
@CrossOrigin
public class PartyConstructionPhotoController {
    @Autowired
    private PartyConstructionPhotoService partyConstructionPhotoService;

    @ApiOperation(value = "增加党建宣传图片", notes = "测试数据:")
    @PostMapping("/insertPartyConstructionPhoto")
    public JsonResult insertPartyConstructionPhoto(@RequestBody Map map){
        JsonResult jsonResult = new JsonResult();
        int i = partyConstructionPhotoService.insertPartyConstructionPhoto(map);
        if (i==1){
            jsonResult.setCode(200);
            jsonResult.setMessage("成功录入党建宣传图片!");
        }else {
            jsonResult.setCode(20006);
            jsonResult.setMessage("录入党建宣传图片失败!");
        }
        return jsonResult;
    }

    @ApiOperation(value = "删除党建宣传图片信息", notes = "测试数据:")
    @PostMapping("/deletePartyConstructionPhoto")
    public JsonResult deletePartyConstructionPhoto(@RequestBody Map map){
        JsonResult jsonResult = new JsonResult();
        List<Integer> list = (List<Integer>) map.get("list");
        int l = 0;
        Map mapR = new HashMap();
        for (int i = 0;i<list.size();i++){
            mapR.put("id",list.get(i));
            int a = partyConstructionPhotoService.deletePartyConstructionPhoto(mapR);
            l+=a;
        }
        if (l>=1){
            jsonResult.setCode(200);
            jsonResult.setMessage("成功删除党建宣传图片!");
        }else {
            jsonResult.setCode(20006);
            jsonResult.setMessage("删除党建宣传图片失败!");
        }
        return jsonResult;
    }

    @ApiOperation(value = "修改党建宣传图片", notes = "测试数据:")
    @PostMapping("/updatePartyConstructionPhoto")
    public JsonResult updatePartyConstructionPhoto(@RequestBody Map map){
        JsonResult jsonResult = new JsonResult();
        int i = partyConstructionPhotoService.updatePartyConstructionPhoto(map);
        if (i==1){
            jsonResult.setCode(200);
            jsonResult.setMessage("成功修改党建宣传图片!");
        }else {
            jsonResult.setCode(20006);
            jsonResult.setMessage("修改党建宣传图片失败!");
        }
        return jsonResult;
    }

    @ApiOperation(value = "分页模糊查询党建宣传图片", notes = "测试数据:")
    @PostMapping("/findPartyConstructionPhotoByPage")
    public Page findPartyConstructionPhotoByPage(@RequestBody Map map) {
        Page page = new Page();
        page.setPageNo((Integer) map.get("pageNo"));
        page.setPageSize((Integer) map.get("pageSize"));
        page.setTotal(partyConstructionPhotoService.Total(map));
        page.setItems(partyConstructionPhotoService.findPartyConstructionPhotoByPage(map));
        return page;
    }

    @ApiOperation(value = "查询全部党建宣传图片", notes = "测试数据:")
    @PostMapping("/selectPartyConstructionPhoto")
    public OneDataResult selectPartyConstructionPhoto(@RequestBody Map map) {
        OneDataResult oneDataResult = new OneDataResult();
        oneDataResult.setData(partyConstructionPhotoService.selectPartyConstructionPhoto(map));
        return oneDataResult;
    }
}
